home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / BSP Tree 1.2 / Sources / Graphics / source / bound_3d.cp next >
Encoding:
Text File  |  1995-03-25  |  4.0 KB  |  58 lines  |  [TEXT/MMCC]

  1. //------------------------------------------------------------------------------
  2. //    File:                    bound_3d.cp
  3. //    Date:                    9/26/94
  4. //    Author:                Bretton Wade
  5. //
  6. //    Description:    this file contains the class methods for a bounding box
  7. //
  8. //------------------------------------------------------------------------------
  9.  
  10. #include "bound_3d.h"
  11.  
  12. //------------------------------------------------------------------------------
  13. //    constructor
  14. //------------------------------------------------------------------------------
  15. bound_3d::bound_3d (void)                                                                                                                //    constructor
  16. {                                                                                                                                                                //    begin
  17.     max (-INFINITY, -INFINITY, -INFINITY);                                                                                //    start max at -inf
  18.     min (INFINITY, INFINITY, INFINITY);                                                                                        //    start min at inf
  19. }                                                                                                                                                                //    end
  20.  
  21. //------------------------------------------------------------------------------
  22. //    self addition
  23. //------------------------------------------------------------------------------
  24. void        bound_3d::operator += (const bound_3d &box)                                                            //    add a bounding box into this one
  25. {                                                                                                                                                                //    begin
  26.     if (box.max[X] > max[X]) max[X] = box.max[X] + EPSILON;                                                //    compare the coordinate value, and replace if the magintude is appropriate
  27.     if (box.max[Y] > max[Y]) max[Y] = box.max[Y] + EPSILON;                                                //    compare the coordinate value, and replace if the magintude is appropriate
  28.     if (box.max[Z] > max[Z]) max[Z] = box.max[Z] + EPSILON;                                                //    compare the coordinate value, and replace if the magintude is appropriate
  29.     if (box.min[X] < min[X]) min[X] = box.min[X] - EPSILON;                                                //    compare the coordinate value, and replace if the magintude is appropriate
  30.     if (box.min[Y] < min[Y]) min[Y] = box.min[Y] - EPSILON;                                                //    compare the coordinate value, and replace if the magintude is appropriate
  31.     if (box.min[Z] < min[Z]) min[Z] = box.min[Z] - EPSILON;                                                //    compare the coordinate value, and replace if the magintude is appropriate
  32. }                                                                                                                                                                //    end
  33.  
  34. //------------------------------------------------------------------------------
  35. //    self addition
  36. //------------------------------------------------------------------------------
  37. void        bound_3d::operator += (const point_3d &pt)                                                            //    add a point_3d into the bounding box
  38. {                                                                                                                                                                //    begin
  39.     if (pt[X] > max[X]) max[X] = pt[X] + EPSILON;                                                                    //    compare the coordinate value, and replace if the magintude is appropriate
  40.     if (pt[Y] > max[Y]) max[Y] = pt[Y] + EPSILON;                                                                    //    compare the coordinate value, and replace if the magintude is appropriate
  41.     if (pt[Z] > max[Z]) max[Z] = pt[Z] + EPSILON;                                                                    //    compare the coordinate value, and replace if the magintude is appropriate
  42.     if (pt[X] < min[X]) min[X] = pt[X] - EPSILON;                                                                    //    compare the coordinate value, and replace if the magintude is appropriate
  43.     if (pt[Y] < min[Y]) min[Y] = pt[Y] - EPSILON;                                                                    //    compare the coordinate value, and replace if the magintude is appropriate
  44.     if (pt[Z] < min[Z]) min[Z] = pt[Z] - EPSILON;                                                                    //    compare the coordinate value, and replace if the magintude is appropriate
  45. }                                                                                                                                                                //    end
  46.  
  47. //------------------------------------------------------------------------------
  48. //    containment test
  49. //------------------------------------------------------------------------------
  50. bool        bound_3d::Contains (const point_3d &pt) const                                                        //    return whether or not a point_3d is inside the bounding box
  51. {                                                                                                                                                                //    begin
  52.     return    bool ((pt[X] <= max[X]) && (pt[X] >= min[X]) &&                                                //    if the x component is in
  53.                                 (pt[Y] <= max[Y]) && (pt[Y] >= min[Y]) &&                                                //    and the y component is on
  54.                                 (pt[Z] <= max[Z]) && (pt[Z] >= min[Z]));                                                //    and the z component is in...
  55. }                                                                                                                                                                //    end
  56.  
  57. //------------------------------------------------------------------------------
  58.